<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" session="false" %>
<%@ page import="com.atozsoft.commonutil.Constants"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="com.eos.data.datacontext.UserObject" %>
<%@ page import="commonj.sdo.DataObject"%>
<%@ page import="org.gocom.components.coframe.rights.dataset.CapUser"%>
<%@ page import="java.math.BigDecimal"%>	
<%@ page import="com.eos.engine.component.ILogicComponent"%>
<%@ page import="com.primeton.ext.engine.component.LogicComponentFactory"%>
	
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- 
  - Author(s): houfy
  - Date: 2016-12-15 14:23:02
  - Description:
-->
<head>
	<%@include file="/common.jsp"%>
	<%@include file="/common/common.jsp"%>
    <%@include file="/coframe/tools/skins/common.jsp"%>
	<title>日常计划审核</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <script src="<%=request.getContextPath()%>/mis/js/uploadify/js/jquery-1.9.1.js" type="text/javascript"></script>
    <script src="<%=request.getContextPath()%>/mis/js/uploadify/js/jquery.uploadify-src.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/mis/js/uploadify/css/uploadify.css">
    <%
        // 来源操作flg
		String actionFlg = "";
		if(request.getParameter("actionFlg")!=null){
			actionFlg = (String)request.getParameter("actionFlg");
		}
		// 计划ID
		String checkid = "";
		if(request.getParameter("checkid")!=null){
			checkid = (String)request.getParameter("checkid");
		}
    	
    	//===== BEG 添加流程实例ID为传入参数，用于查询实体数据  add 2014-12-09 houfy
    	//流程实例ID
 	 	String processInstId = "";
		if(request.getParameter("processInstId")!=null){
			processInstId = (String)request.getParameter("processInstId");
		}
		
		//流程实例工作项ID
 	 	String workitemid = "";
		if(request.getParameter("workitemid")!=null){
			workitemid = (String)request.getParameter("workitemid");
		}
		
		//节点名称
		String activitydefid = "";
		if(request.getParameter("activitydefid")!=null) {
			activitydefid = (String)request.getParameter("activitydefid");
		}else{
			activitydefid = "null";
		}
		//打开方式
		String webType = "";
		if(request.getParameter("webType")!=null) {
			webType = (String)request.getParameter("webType");
		}
 	 	//===== END 添加流程实例ID为传入参数，用于查询实体数据  add 2014-12-09 houfy
	%>
</head>
<body>
	<div id="showbtnArea" class="nui-toolbar" style="padding:0px;" borderStyle="border:0;">
			<table width="100%">
		    	<tr>
		        	<td style="text-align:right;">
		          		<!-- <a id="editBtn" class="nui-button" iconCls="icon-edit" onclick="onEdit">编辑</a>
		          		<span style="display:inline-block;width:10px;"></span> -->
		          		<!-- <a id="okBtn" class="nui-button" iconCls="icon-save" onclick="onOk">保存</a> -->
		          		<a id="submitBtn" class="nui-button" style="width:60px;" iconCls="icon-upload" onclick="submit()">提交</a>
		          		<span style="display:inline-block;width:10px;"></span>
		        	</td>
		      	</tr>
		    </table>
		</div>
	<div id="editWorkplanCheckForm" style="padding-top:30px;">
		<!-- 计划审核ID -->
  		<input id="checkid" class="nui-hidden" name="check.checkid"/>
  		<input id="status" class="nui-hidden" name="check.status"/>
    	<table style="width:100%;height:100%;table-layout:fixed;" class="nui-form-table">
      		<tr>
      			<th class="nui-form-label"><font color="red">*</font>&nbsp;计划年份：</th>
        		<td>
        			<input id="planyear" class="nui-textbox nui-form-input" name="check.planyear"   style="width: 100%;"  required="true" requiredErrorText="计划年份不能为空！"/>
        		</td>
        		<th class="nui-form-label"><font color="red">*</font>&nbsp;计划月份：</th>
        		<td>
        			<input id="planmonth" class="nui-textbox nui-form-input" name="check.planmonth"   style="width: 100%;"  required="true" requiredErrorText="计划月份不能为空！"/>
        		</td>
      		</tr>
      		<tr>
      			<th class="nui-form-label"><font color="red">*</font>&nbsp;编制人：</th>
        		<td>
        			<input id="compilation" class="nui-buttonedit"  name="check.compilation" textName="check.compilationname" style="width:100%" onbuttonclick="userData1" allowInput="false" required="true" requiredErrorText="编制人不能为空！"/>
        		</td>
        		<th class="nui-form-label"><font color="red">*</font>&nbsp;编制日期：</th>
        		<td>
        			<input id="compilationdate" class="nui-datepicker" style="width:100%;"  name="check.compilationdate" allowInput="false" required="true" requiredErrorText="编制日期不能为空！"/>
        		</td>
      		</tr>
      		<tr>
        		<th class="nui-form-label">备注：</th>
        		<td  colspan="3">
          			<input id="remark" class="nui-textarea nui-form-input" name="check.remark" vtype="rangeChar:0,1300" rangeCharErrorText="备注长度不能超过1300！"/>
          			<!-- 附件 -->
          			<input id="attachment" class="nui-hidden" name="check.attachment"/>
        		</td>
      		</tr>
    	</table>
    	<div class="nui-fit">
	  		<div id="workplancheckDataGrid" class="nui-datagrid" style="width:100%;height:300px;"
	  		 url="com.shendong.mis.workPlan.queryWorkplanForCheck.biz.ext" dataField="datas"
	          	sizeList=[10,20,50,100] multiSelect="true" pageSize="50" allowAlternating="true">
	        	<div property="columns">
	        		<div field="planid" visible="false">ID</div>
	          		<div type="checkcolumn" name="lie" headerAlign="center" align="center">
	          		</div>
	          		<div field="plantheme" allowSort="true" headerAlign="center" renderer="urlRenderer" width="200px">
	        			计划标题
	          		</div>
	          		<div field="planyear" allowSort="true" headerAlign="center" >
	        			计划年度
	          		</div>
	          		<div field="planmonth" allowSort="true" headerAlign="center">
	        			计划月份
	          		</div>
	          		<div field="plantype" allowSort="true" headerAlign="center" renderer="onRender">
	        			计划类型
	          		</div>
	          		<div field="status" allowSort="true" headerAlign="center" renderer="onRender"  visible="false">
	        			数据状态
	          		</div>
	          		<div field="creatername" allowSort="true" headerAlign="center" visible="false">
	            		创建者
	          		</div>
	          		<div field="createdate" allowSort="true" headerAlign="center" align="center" dateFormat="yyyy-MM-dd" visible="false">
	            		创建日期
	          		</div> 
	          		<div field="processinstid" visible="false">流程实例ID</div>
	        	</div>
	      	</div>
	    </div>
		<div style="width:100%;padding:2px 0px 0px 0px;">
			<div class="nui-toolbar" style="border-bottom:0;">
	        	<table style="width:100%;">
	            	<tr>
			            <td style="width:50%;">
			                <a class="nui-button" id="uploadify">上传</a>
			            	<a id="deleteFile" class="nui-button" onclick="removeFile()" style="margin-left: 85px; width:60px;">删除</a>
			            </td>
				    	<th align="left">附件</th>
		            </tr>
		        </table>
	    	</div>
	    </div>
    	<div class="nui-fit" style="width:100%;min-height: 83px;height: 85px;">
  			<div id="attachmentDatagrid" class="nui-datagrid" style="width:100%;height:100%" sizeList="[5,10,20,50]"  
  				idField="fileid" dataField="cmFiles" url="com.austar.cm.common.queryUplodeFileListByIds.biz.ext" 
		    	allowResize="false" showPager="false" showReloadButton="false" totalField="total" multiSelect="true">
		    	<div property="columns">
		        	<div field="fileid" visible="false">ID</div>
		        	<div field="filepath" visible="false">路径</div>
          			<div name="checkcolumn" type="checkcolumn" headerAlign="center" width="10px" align="center"></div>
		        	<div type="indexcolumn" headerAlign="center" width="20px" align="center">序号</div>
		        	<div field="uploadname" headerAlign="center" allowSort="true" renderer="renderOnfileName">文件名称</div>
		    	</div>
			</div>
	    </div>
	</div>
	<script type="text/javascript">
		//数据渲染处理
    	function onRender(e){
    		if(e.field=="plantype"){
    			return nui.getDictText("MIS_PLANTYPE",e.value);
    		}else if (this.field=="status"){
        	    if(e.row.status == "2"){
        	    	dictText = "<a href='#' onclick='showWFgraph("+e.row.processinstid+");'>已审核</a>";
        	    }else if(e.row.status == "1"){
        	    	dictText = "<a href='#' onclick='showWFgraph("+e.row.processinstid+");'>审核中</a>";
        	    }else{
	        	    if(e.row.processinstid != "" && e.row.processinstid != null){
	        	    	dictText = "<a href='#' onclick='showWFgraph("+e.row.processinstid+");'>保存</a>";
	        	    }else{
	        	    	dictText = "保存";
	        	    }
        	    }
        		return dictText;
    		}
    	}
     	
     	//跳转方式修改为弹出TAB
    	var postUrl="<%=request.getContextPath()%>/mis/common/postUrl.jsp?";
     	
     	// 跳转页面
     	function onUrl(actionFlg,planId,processInstId,workitemid,title){ 
			// 跳转页面并传参（post）      
			addDetailTab(actionFlg,planId,processInstId,workitemid,title);		 
		}
		
		/*
		* 重新打开一个tab页显示详细页面
		* actionFlg: 操作类型
		* guaranteeletterId: ID
		*/
      	function addDetailTab(actionFlg,planId,processInstId,workitemid,title){
      		var url ="<%=request.getContextPath()%>/mis/workPlan/workPlan_detail.jsp"; 
      		
			var params=nui.encode({actionFlg:actionFlg,planId:planId,processInstId:processInstId,workitemid:workitemid});
			var tabName = "plan_menu";
			if(planId != null && planId != ""){
				tabName = tabName + "_" +planId;
			}
			window.parent.parent.addtabs(postUrl+"url="+url+"&params="+encodeURIComponent(params),title, tabName); 
      	} 
        
        // 数据链接跳转相关
      	function urlRenderer(e) 
      	{	
      		return "<a class='viewbutton' href='javascript:void()' onclick=onUrl('process','"+e.row.planid+"','"+e.row.processinstid+"','','日常计划明细')>"+e.row.plantheme+"</a>";
     	}
    	
    	nui.parse();
    	
    	var form = new nui.Form("#editWorkplanCheckForm");
    	var gridwp = nui.get("workplancheckDataGrid");
    	var grid = nui.get("attachmentDatagrid");
    	var actionFlg="<%=actionFlg%>";
    	var checkid="<%=checkid%>";
    	var uploadFlg = true;
    	var processInstId = "<%=processInstId %>" ;
	    var workitemid ="<%=workitemid%>";
	    var activitydefid = "<%=activitydefid %>";
 		var webType = "<%=webType %>";
    	 
    	if(actionFlg=="add" || actionFlg=="processStart")
    	{
    		gridwp.load();
    		gridwp.sortBy("createdate", "desc");
		    
    	}else if(actionFlg=="process"){
    		//从流程业务关系表中查询关系数据
    		if (processInstId!=null && processInstId!= ""){
    			var processJson =  nui.encode({processInstId:processInstId});
    			$.ajax({
			        url:"com.atozsoft.wf.processOperate.queryProcessBusinessRelationByID.biz.ext",
			        type:'POST',
			        data:processJson,
			        cache:false,
			        async:false,// 禁止异步加载
			        contentType:'text/json',
			        success:function(text){
			        	checkid = text.pBusiness.keyvalue;
			        },
	                error: function () {
	                	nui.alert("数据异常！", "提示");
	                }
		      	});
    		} 
	
    		var pbJson  = nui.encode({checkid:checkid});
    		
    		//各种监听事件
		    $.ajax({
			     url:"com.shendong.mis.workPlan.queryWorkplanCheckbyID.biz.ext",
			     type:'POST',
			     data:pbJson,
		         contentType:'text/json',
		 	     async:false,
		 	     cache:false,
		 	     success:function(text){
		 	        form.setData(text);
                    form.setChanged(false);
                    nui.get("checkid").setValue(text.check.checkid);
                    nui.get("status").setValue(text.check.status);
                    
                    gridwp.load({checkid:text.check.checkid});
					gridwp.sortBy("createdate", "desc");
		 	     }
		   });	
    	}else{
    		var json = nui.encode({checkid:checkid});
		     //各种监听事件
			$.ajax({
			     url:"com.shendong.mis.workPlan.queryWorkplanCheckbyID.biz.ext",
			     type:'POST',
			     data:json,
		         contentType:'text/json',
		 	     async:false,
		 	     cache:false,
		 	     success:function(text){
		 	        form.setData(text);
                    form.setChanged(false);
                    nui.get("checkid").setValue(text.check.checkid);
                    nui.get("status").setValue(text.check.status);
                   
                    gridwp.load({checkid:text.check.checkid});
					gridwp.sortBy("createdate", "desc");
		 	     }
			});	
    	}
    	
    	//设定页面字段显示式样
    	setViewClass(actionFlg);
        
	    // 设置编辑样式
		function setViewClass(flg){
			if(flg=="add" || flg =="processStart"){
				
			}else if(flg=="update"){
				
			}else if(flg=="process"){
				nui.get("planyear").disable();
				nui.get("planmonth").disable();
				nui.get("compilation").disable();
				nui.get("compilationdate").disable();
				nui.get("remark").disable();
				gridwp.hideColumn("lie");
				var status = nui.get("status").getValue();
				if(status=="0"){
					nui.get("submitBtn").enable();
				}else{
					nui.get("submitBtn").disable();
				}
				
				//按钮隐藏
				$("#showbtnArea").hide();
			}else{
				//按钮隐藏
				$("#showbtnArea").hide();
				
				nui.get("planyear").disable();
				nui.get("planmonth").disable();
				nui.get("compilation").disable();
				nui.get("compilationdate").disable();
				nui.get("remark").disable();
				nui.get("submitBtn").disable();
				gridwp.hideColumn("lie");
			}
	      
	    }
    	
    	//PROCESS BEG ============== 流程操作代码 ==============
		
    	// 设置不可编辑样式
        function noEdit(){
		    setViewClass();
        }
	    
		// 提交
	    function submit(){
			var checker = "";
	        
	        nui.open({
	            url: "<%=request.getContextPath()%>/mis/orgUser/selectEmployee.jsp?processInstId=" + processInstId+ "&workitemid="+workitemid+"&empid=N&role=6",
		        title: "审批者选择",
				width: 870,
                height: 550,
                onload: function () {
                	var iframe = this.getIFrameEl();
			        iframe.contentWindow.SetData({multiSelect:'false'});
                },
                ondestroy: function (action) {
              	 	if(action=="ok"){
              	 		var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = nui.clone(data);    //必须克隆返回值
                        // 审批人选定赋值
                        checker = data.empid;  
                        submitData(checker); 	
                    }
                }
		    });
		}
		
		// 提交
	    function submitData(checker){
	     	var rows = gridwp.getSelecteds();
	     	//alert(rows);
	        var form = new nui.Form("#editWorkplanCheckForm");
	        form.setChanged(false);
	        //流程发起
	        var urlStr = "com.shendong.mis.workPlan.submitWorkPlanCheck.biz.ext";
	        form.validate();
	        if(form.isValid()==false) return;
	        var data = form.getData(false,true);
	        if(checker == "" || checker == null) return;
	        var json = nui.encode({checker:checker,check:data.check,plans:rows});
	        $.ajax({
	        	url:urlStr,
	        	type:'POST',
	        	data:json,
	        	cache:false,
	        	contentType:'text/json',
	        	success:function(text){
	            	var returnJson = nui.decode(text);
	            	if(returnJson.resultStr == "success"){
	              		nui.get("checkid").setValue(text.check.checkid);
	              		nui.alert("流程发起成功！");
			            //更新页面状态
			            actionFlg="process";
			            setViewClass(actionFlg);
	              
	           		}else{
	              		nui.alert("流程发起失败", "系统提示", function(action){
			                if(action == "ok" || action == "close"){
			                  //CloseWindow("saveFailed");
			                }
	               		});
	             	}
	           	}
	        });
	    }
	    
	    // 流程执行父页面调用接口
        var checkSet = "";
	    
		 //获取节点选择窗口的筛选值
	    function getCheckSet(){
        		return checkSet;
        }
	    // 流程执行父页面调用接口
        parent["infoFrame"] = window;
         // 父页面调用的字段控制操作
        // 01 显示 工时（workhours）字段
	    //传递控制参数
       var parentWorkType = "2345";
       
       function onParentCallCheck(){
       		var str = "false";
	        return str;
       	}
       
        // 父页面调用的保存操作，同意操作打开之前执行
	    function onParentCallOk(){
	        // 设定保存返回值   
        	var resultStr = "";
	        return resultStr;
	    }
	    
	    // 工作项确认同意后调用的操作
	    function onParentCallAfterOk(){
	    }
	    
	    // 流程与业务参数传递函数
	    function onParentEditParams(){
	    
	    }
	    
	    // 等待提示
		function loading(){
			nui.mask({el: document.body,cls: 'mini-mask-loading',html: '处理中...'});
		}
		
		// 结束等待提示
	    function endLoading(){
	    	nui.unmask(document.body);
    	}
    	
	    // 流程完成后，打开页面查看时调用的操作
	    function onParentCallAfterStop(){
	    	
	    }
	    
	    // 父页面调用的打印操作
	    function onParentCallPrint(){
	    	//parent.printPage();
	    }
	    
	    // 更新流程业务关系表
	    function updatePBRelation(){
	    }

	    
	  	//PROCESS END ============== 流程操作代码 ==============

		//编制人的点击函数
        function userData1(){
	    	nui.open({
                url: "<%=request.getContextPath()%>/mis/orgUser/selectEmployee.jsp",
                title: "用户",
                width: 870,
                height: 550,
                onload: function () {
                	var iframe = this.getIFrameEl();
			        iframe.contentWindow.SetData({multiSelect:'false'});
                },
                ondestroy: function (action) {
              	 	if(action=="ok"){
              	 		var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = nui.clone(data);    //必须克隆返回值
                       /*  alert(nui.encode(data)); */
                        // 主管所领导赋值
                        nui.get("compilation").setValue(data.empid);
                        nui.get("compilation").setText(data.username);     	 	
                    }
                }
            });
	    }
		//写完treeSelect必须加这个函数，要不选不到
    	function beforenodeselect(e) {
            //禁止选中父节点
            if (e.isLeaf == false) e.cancel = true;
        }
    </script>
</body>
</html>